package com.blog.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.blog.anno.ServiceLogAnno;
import com.blog.dao.ArticleMapper;
import com.blog.entity.Article;
import com.blog.service.IArticleService;
import com.blog.vo.PageVo;


@Service
@Transactional
public class ArticleServiceImpl implements IArticleService {

	@Autowired
	private ArticleMapper dao;

	@Override
	@ServiceLogAnno("文章 - 分页查询")
	public PageVo findPage(String typeId,String title,Integer pageNum, Integer pageSize,String username) {
		PageVo pageVo = new PageVo();
		pageVo.setPageNum(pageNum);
		pageVo.setPageSize(pageSize);
		pageVo.setList(dao.pageList(typeId,(title==null||title.equals("")?"":"%"+title+"%"),(pageNum - 1) * pageSize, pageSize,username));
		pageVo.setTotalCount(dao.totalCount(typeId,title,username).intValue());
		return pageVo;
	}

	
	@Override
	@ServiceLogAnno("文章 - 发表")
	public int save(Article article) {
		return dao.save(article.getId(),article.getTitle(), article.getInfo(), article.getText(), article.getUserId(), article.getTypeId(),article.getPageViewId());
	}

}
